{*******************************************************************************
* The contents of this file are used with permission, subject to the Mozilla   *
* Public License Version 1.1 (the "License"); you may not use this file except *
* in compliance with the License. You may obtain a copy of the License at      *
* http://www.mozilla.org/MPL/                                                  *
*                                                                              *
* Software distributed under the License is distributed on an "AS IS" basis,   *
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for *
* the specific language governing rights and limitations under the License.    *
*                                                                              *
* The Original Code is distributed as part of the "mediate" product and is     *
* Copyright (C) @home media limited. All Rights Reserved.                      *
*                                                                              *
* Email: support@athomemedia.co.uk                                             *
* Web:   http://www.athomemedia.co.uk                                          *
*******************************************************************************}

unit TextEdits;

interface

uses Classes, VButtons, UIObjects;

{$IFDEF DESIGNER}
const
  // Property hints for designer
  HINT_STATES = 'defines bitmaps or shapes for each text edit state';
  HINT_FONTS = 'defines fonts for each text edit state (overrides caption font)';
  HINT_CAPTIONS = 'defines captions for each text edit state (overrides default caption)';
  HINT_CAPTION = 'defines default caption for all text edit states';
  HINT_WIDTH = 'specifies width for the text edit';
  HINT_HEIGHT = 'specifies height for the text edit';
{$ENDIF}

type
  TAHMTextEdit = class(TAHMButton)
  public
    constructor Create(const Name: String); override;
    procedure BuildProperties(Properties: TAHMUIPropertyList); override;
  end;

  TAHMTextEditList = class(TAHMUIObjectList)
  private
  protected
  public
    constructor Create; override;
    function AddTextEdit(const InheritFrom, NewName: String): TAHMTextEdit;
    function GetTextEdit(const Name: String): TAHMTextEdit;
    procedure PopulateDefaultObjects; override;
  end;


implementation

uses ApplicationManager, BaseControls, Captions, TagNames, AHMTypes;


constructor TAHMTextEditList.Create;
begin
  inherited Create;

  XMLTagName := TAG_TEXTEDITS;
  ChildClass := TAHMTextEdit;
end;

function TAHMTextEditList.AddTextEdit(const InheritFrom, NewName: String): TAHMTextEdit;
begin
  Result := TAHMTextEdit(Inherit(InheritFrom, NewName));
end;

function TAHMTextEditList.GetTextEdit(const Name: String): TAHMTextEdit;
begin
  Result := TAHMTextEdit(GetObject(Name));
end;

procedure TAHMTextEditList.PopulateDefaultObjects;
begin
  with ApplicationManagerInstance.ThemeManager, DefaultObject as TAHMButton do
  begin
    VirtualWidth := DEFAULT_CTRL_WIDTH;
    VirtualHeight := DEFAULT_CTRL_HEIGHT div 2;
    VirtualCaptionX := DEFAULT_CTRL_HEIGHT div 10;
    VirtualCaptionY := DEFAULT_CTRL_HEIGHT div 10;
    States.AddObject(STATE_VAL_IDLE, ThemeObjects[otShapes].DefaultObjects[STATE_VAL_IDLE]);
    States.AddObject(STATE_VAL_FOCUS, ThemeObjects[otShapes].DefaultObjects[STATE_VAL_FOCUS]);
    States.AddObject(STATE_VAL_DISABLE, ThemeObjects[otShapes].DefaultObjects[STATE_VAL_DISABLE]);
    Caption := TAHMCaption(ThemeObjects[otCaptions].DefaultObject);
  end;
end;

//----------------------------------------------------------------------------//

constructor TAHMTextEdit.Create(const Name: String);
begin
  inherited Create(Name);

  XMLTagName := TAG_TEXTEDIT;
  ObjectType := otTextEdits;
  ImageIndex := Ord(otTextEdits);

{$IFDEF DESIGNER}
  States.DisplayClassName := 'Text Edit state';
  StateFonts.DisplayClassName := 'Text Edit font';
  StateCaptions.DisplayClassName := 'Text Edit caption';
{$ENDIF}
end;

procedure TAHMTextEdit.BuildProperties(Properties: TAHMUIPropertyList);
begin
{$IFDEF DESIGNER}
  inherited;

  // Remove button properties so we can override hints
  Properties.Remove('States');
  Properties.Remove('StateFonts');
  Properties.Remove('StateCaptions');
  Properties.Remove('Caption');
  Properties.Remove('VirtualWidth');
  Properties.Remove('VirtualHeight');

  // Build custom text edit properties
  Properties.Add('States', 'States', CAT_APPEARANCE, HINT_STATES);
  Properties.Add('Fonts', 'StateFonts', CAT_APPEARANCE, HINT_FONTS);
  Properties.Add('Captions', 'StateCaptions', CAT_APPEARANCE, HINT_CAPTIONS);
  Properties.Add('Default Caption', 'Caption', CAT_APPEARANCE, HINT_CAPTION);
  Properties.Add('Width', 'VirtualWidth', CAT_DESIGN, HINT_WIDTH);
  Properties.Add('Height', 'VirtualHeight', CAT_DESIGN, HINT_HEIGHT);
{$ENDIF}
end;


end.

